﻿#ifndef DEALCHARTDATA_H
#define DEALCHARTDATA_H

#include <QObject>
#include <QMap>
#include <QFile>
#include <QDataStream>
#include <QVector>
#include "pdxpmodel.h"
#include "udfmodel.h"
#include "SqliteUtil/sqliteutil.h"

#define TM "TimePoint"
#define COUNT 5000
#define SPILECOUNT 50000

class DealChartData : public QObject
{
    Q_OBJECT
public:
    explicit DealChartData(QObject* parent = 0);


    QMap<QString, QMap<QString, long long>> getBarData();

    QMap<QString, QMap<QString, long long>> getLineData();
    QMap<double, double> getSplineData();

    QMap<int, int> getNormalityDtata();
    int getSplieMaxData();
    void splitBarData();
    void splitLineData();

    bool isCreateTab(const QString& fileName);

    void initData(const QString& fileName, int nIndex = 0);


    void initDB();
    void disDB();

    void initSplinData(const QString& fileName);
    void fetchMore();


    void getProssBarValue(int& row1, int& row2, int& rowMax2);

    void DiscontinueInsert();


    SqliteUtil m_db;

signals:


private:

    void clear();
    bool calcRecords();

    bool calcSplineRecords();

    int maxDisplaySize(void) const;
    void loadBarRecord();
    void loadLineRecord();


    QString jsBarSecString(quint32 js);
    QString jsBarMinString(quint32 js);
    QString jsLineString(quint32 js);
private:
    QMap<QString, QMap<QString, long long>> barData;
    QMap<QString, QMap<QString, long long>> lineData;
    QMap<QString, long long> qBarDatas;

    QList<qint64> qLineDatas;
    QFile file;
    PDXP pdxp;
    UDF udf;
    QByteArray record;
    QVector<qint64> records;

public:

    int m_nIndex;

    int m_nCount;

    int m_nUnit;

    int m_nRow;

    int m_nPos;

    bool m_bPos;

    QString m_strInfo;


    qreal qRow;
    bool m_bDiscontinue;

    int m_nView;
};

#endif // DEALCHARTDATA_H
